package groupId.config;

import groupId.api.AuthToken;
import groupId.api.CarrierApi;
import groupId.api.MoxieApiFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Desc:
 * Author:liubo
 * Date: 2017-07-05 15:18
 **/
@Configuration
public class MoxieConfig {
    @Value("${moxie_apikey}")
    private String apikey;

    @Value("${moxie_token}")
    private String token;

    @Value("${moxie_baseurl}")
    private String baseUrl;

    @Bean(name = "moxieApiFactory")
    public MoxieApiFactory getMoxieApiFactory(){
        MoxieApiFactory  moxieApiFactory = MoxieApiFactory.builder()
                .withAuthToken(new AuthToken(apikey, token))
                .withBaseUrl(baseUrl)
                .build();
        return moxieApiFactory;
    }

    @Bean
    public CarrierApi carrierApi(@Qualifier("moxieApiFactory")MoxieApiFactory moxieApiFactory){
        CarrierApi carrierApi = moxieApiFactory.newApi(CarrierApi.class);
        return  carrierApi;
    }
}
